<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
	<title>提现</title>
	<script src="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/frame/mui/js/mui.min.js"></script>
	<link href="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/frame/mui/css/mui.min.css" rel="stylesheet" />
	<link rel="stylesheet" href="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/frame/sui/css/SUI.css">
	<link rel="stylesheet" href="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/css/app.css?v=4">
	<link href="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/frame/mui/css/mui.picker.css" rel="stylesheet" />
	<link href="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/frame/mui/css/mui.poppicker.css" rel="stylesheet" />
	<script src="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/frame/mui/js/mui.picker.js"></script>
	<script src="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/frame/mui/js/mui.poppicker.js"></script>
</head>
<style>
	.suiLineInput dl input{margin: 0!important;padding:0;}
	.suiLineInput dl{min-height: 41px !important}
	.suiTag{margin: 0}
	.sure{margin-bottom: 20px;}
	button.mui-btn{border: #e54242}
	.takecash .hd dl.obj[type=bank] dt:after{content: ''}
	.takecash .hd dl.obj dt:after{content: ''}
</style>
<body class="takecash">
	<div class="content">
	<div class="hd">
		<dl class="box">
			<dt class="suiBgImg" style="background-image: url({{.info.pathname}});"></dt>
			<dd>{{.info.money}}</dd>
		</dl>
		<dl class="center">
			<dt>当前转账金额</dt>
			<dd class="money"></dd>
		</dl>
		<dl class="box obj" type="bank">
			<dt class="suiBgImg" id="bankimg"></dt>
			<dd id="banktype">银行卡</dd>
		</dl>
	</div>
	<div class="suiLineBox notop strong">
		<dl>
			<dt>到账时间</dt>
			<dd>三个工作日内</dd>
		</dl>
	</div>
	<form id="form">
		<div class="suiLineInput strong">
			<dl>
				<dt>提款银行</dt>
				<dd id="bank">请选择提款银行</dd>
				<input type="hidden" name="bank">
			</dl>
			<dl>
				<dt>姓名</dt>
				<dd><input type="text" placeholder="请填写收款人姓名" name="name"></dd>
			</dl>
			<dl>
				<dt>收款卡号</dt>
				<dd><input type="text" placeholder="请填写收款卡号" name="account"></dd>
			</dl>
			<dl>
				<dt>提现金额</dt>
				<dd><input type="tel" name="money" pattern="[0-9]*"  placeholder="请输入提现金额"></dd>
			</dl>
			<dl>
				<dt>提现密码</dt>
				<dd><input type="password" name="cashpassword"  placeholder="请输入提现密码"></dd>
			</dl>
		</div>
	</form>
	<p class="suiBasicText">Tip：提交提现申请后，我们将在三个工作日内完成审核，请您耐心等待，如有疑问，可拨打{{.system.tel}}进行咨询</p>
	<button class="sure">申请提现</button>
	</div>
</body>
</html>
<!-- 请更新sui -->
<script type="text/javascript" src="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/frame/sui/js/SUI.js?v2"></script>
<script type="text/javascript" src="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/js/card.js"></script>
<script type="text/javascript" src="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/js/sword_uppic.js"></script>
{{template "wechat/public/share.html" .}}
<script type="text/javascript">
	var userPicker = new mui.PopPicker();
	userPicker.setData([{{range .bank}}{
		text: '{{.name}}',
		value:'{{.id}}',
		src:'{{.pathname}}'
	},{{end}}]);
	var bank = document.getElementById('bank');
	var bank2=document.getElementsByName("bank")[0]
	var bankimg=document.getElementById("bankimg")
	var banktype=document.getElementById("banktype")
	bank.addEventListener('tap', function(event) {
		userPicker.show(function(items) {
			bank.innerHTML =items[0].text;
			bank2.value=items[0].value
			bankimg.style.backgroundImage="url("+items[0].src+")";
			banktype.innerHTML =items[0].text;
		});
	}, false);
	var obj = document.querySelector(".obj"),
		money = document.querySelector("input[name=money]")
		type = ["bank","alipay","wxpay"]
	function showMoney(value){
		var value = value.replace(/[a-zA-z]/,'')
		switch (value.split(".").length) {
			case 2:
				// statements_1
				document.querySelector(".money").innerText = value + (value.split(".")[1].length == 1?'0':value.split(".")[1].length == 0?'00':'')
				break;
			default:
				document.querySelector(".money").innerText = value + (value==''?'0':'') + ".00"
				// statements_def
				break;
		}
	}
	money.oninput = function(){
		showMoney(this.value)
	}
	var money={{.info.money}};
	var havepass=0
	{{if .info.cashpassword}}
	{{if ne .info.cashpassword ""}}
	havepass=1
	{{end}}
	{{end}}
	window.onload=function(){
		if(havepass==0){
			document.getElementsByClassName('content')[0].style.display="none"
			mui.confirm("您还未设置提现密码,前往设置吗?","提示",function(res){
				if(res.index){
					mui.closePopups()
					window.location.href="/mobile/my/info_safe_changep?type=cash"
				}else{
					window.location.href=document.referrer
				}
			}); 
			return false;
		}
	}
	document.getElementsByClassName("sure")[0].addEventListener('tap',function(){
		var form=serialize('form')
		if(parseInt(form.money)<=parseInt({{.system.cash}})){
			mui.toast("一次需要提现{{.system.cash}}元以上~"); return false;
		}
		if(parseInt(form.money)>parseInt(money)){
			mui.toast("余额不足~"); return false;
		}
		if(form.name==""){
			mui.toast("请输入账户名字"); return false;
		}
		if(form.bank==""){
			mui.toast("请选择提现银行"); return false;
		}
		if(form.cashpassword==""){
			mui.toast("请输入提现密码"); return false;
		}
		if(form.account.length!=16&&form.account.length!=19){
			mui.toast("卡号位数错误"); return false;
		}else{
			if(!luhmCheck(form.account)){
				mui.toast("卡号未通过校验,请检查~"); return false;
			}
		}
		var that=this
		that.disabled=true
		mui.ajax(window.location.href,{
			type:'post',
			data:form,
			dataType:'json',
			timeout:10000,
			success: function(data){
			if (data==1) {
				mui.alert("提交成功，请等待审核","",function () {
					window.location.href="/mobile/my"
				});
			}else if(data==2){
				mui.toast("余额不足~")
			}else if(data==3){
				mui.toast("密码错误~");
			}else if(data==4){
				mui.toast("您需要预留{{.system.shopcash}}元");
			}else{
				mui.toast("网络繁忙，请重试~");
			}
			that.disabled=false
			},
			error: function(xhr, type){
				mui.toast("网络慢，请重试");
				that.disabled=false
			// 即使加载出错，也得重置
			}
		});
	})
</script>
